﻿using CatUtils.Utils.Currency.IoUtils;
using CatUtils.Utils.Currency.TextUtils;
using CatUtils.Utils.Helper;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types;
using Telegram.UserTool.TelegramInfo;

namespace Telegram
{
    public partial class MainView : Form
    {
        public MainView()
        {
            InitializeComponent();
            FloderHelper.InitFloder();
            InitClient();
        }

        private static void InitClient()
        {
            botClient = new TelegramBotClient(BotToken);
            var me = botClient.GetMeAsync().Result;
            Console.WriteLine(
              $"Hello, World! I am user {me.Id} and my name is {me.FirstName}."
            );

            botClient.OnMessage += Bot_OnMessage;
            botClient.StartReceiving();
        }

        private static ITelegramBotClient botClient;
        public static string BotToken = "825392576:AAEfPKvUzs1THz3VT5r-lP5vrR1C_vB0FtE";

        private void button1_Click(object sender, EventArgs e)
        {
            //      Thread.Sleep(int.MaxValue);

            // BaiduTextHelper.SentimentClassify(textBox1.Text);
            //   BaiduCurrencyHelper.SaveNplInfo(BaiduTextHelper.API_KEY_Path, BaiduTextHelper.SECRET_KEY_Path, "CQ5qTlEQaK4ziFK2UQWVX0BO", "Zb50vv8DmYdvr8vNGZiEoXYiIdmeEe2Z", new Baidu.Aip.Nlp.Nlp("", ""));
            //Console.WriteLine(MkblogHelper.UploadFile(FileHelper.SelectFile()));
        }

        private static async void Bot_OnMessage(object sender, MessageEventArgs e)
        {
            if (e.Message.Text != null)
            {
                await TelegramHelper.SendMessageAsync(botClient, "", e.Message.Chat.Id);
            }
            if (e.Message.Sticker != null)
            {
                Bot.Types.File file = await botClient.GetFileAsync(e.Message.Sticker.FileId);

                string DownloadFloder = StaticValue.TempPath + e.Message.Sticker.SetName + "\\";
                if (FloderHelper.FloderExits(DownloadFloder, false))
                {
                    Console.WriteLine("文件夹已存在");
                }
                else
                {
                    FloderHelper.FloderExits(DownloadFloder, true);
                }
                await TelegramHelper.DownloadStickers(botClient, e.Message.Sticker.SetName, DownloadFloder, BotToken);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FloderHelper.OpenFloder(".\\");
        }
    }
}